#ifndef __PCPT_COMM_IOU_H__
#define __PCPT_COMM_IOU_H__

#include "comm/comm_base.h"
#include "comm/comm_data_type.h"

using namespace std;

#define LIMITO      1E-8
#define SIG(x_)     (x_ > LIMITO) - (x_ < -LIMITO)    //返回-1, 0, 1

struct POINT_2D_STRU {
    POINT_2D_STRU(){}
    
    POINT_2D_STRU(float x_, float y_) : x(x_), y(y_) {}

    bool operator == (const POINT_2D_STRU& stPoint) const {
        return SIG(x - stPoint.x) == 0 && SIG(y - stPoint.y) == 0;
    }

    float x;
    float y;
};

/**************************************************************************************
功能描述: IoU(交并比)
修改记录:
**************************************************************************************/
class IOU_C
{
public:
    IOU_C(){}

    ~IOU_C(){}
    
    double PloygonArea(const vector<COORDINATE_2D_STRU> &vstPoint) const;
    float  IoUOfRectangle(RECTANGLE_STRU &stRect1, RECTANGLE_STRU &stRect2) const;
    float  IoUOfPolygon(const vector<COORDINATE_2D_STRU>& vstCoor1, const vector<COORDINATE_2D_STRU>& vstCoor2);

private:
    double DirectedArea(POINT_2D_STRU* pPolygon, int pointNum) const;
    double DirectedArea(const vector<POINT_2D_STRU>& polygon) const;
    float  CrossProduct(POINT_2D_STRU& stPointO, POINT_2D_STRU& stPointA, POINT_2D_STRU& stPointB);
    int   LineCross(POINT_2D_STRU& pointA, POINT_2D_STRU& pointB, POINT_2D_STRU& pointC, POINT_2D_STRU& pointD, POINT_2D_STRU& pointT);
    void  PolygonCut(vector<POINT_2D_STRU>& polygon, POINT_2D_STRU& pointA, POINT_2D_STRU& pointB);
    float IntersectArea(POINT_2D_STRU pointA, POINT_2D_STRU pointB, POINT_2D_STRU pointC, POINT_2D_STRU pointD);
    float IntersectArea(vector<POINT_2D_STRU>& polygon1, vector<POINT_2D_STRU>& polygon2);
    float IoUPolygon(vector<POINT_2D_STRU>& poly1, vector<POINT_2D_STRU>& poly2);    
};


#endif

